package com.cat.dataStructure03;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/find-the-minimum-possible-sum-of-a-beautiful-array/
 * @create 2025/11/21 16:08
 * @since JDK17
 */

public class Solution98 {
    public int minimumPossibleSum(int n, int target) {
        int N = ((int) 1e9) + 7;
        long pre = target / 2, suf = n - pre;
        int x = ((int) ((1 + pre) * pre / 2 % N));
        if (pre > n) {
            return ((int) ((1l + n) * n / 2 % N));
        }
        return (int) ((x + (target + target + suf - 1) * suf / 2) % N);
    }
}
